﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dycox.Workflows
{
    public abstract class TransitionOperation
    {
        private Transition _transition;

        public Transition Transition
        {
            get { return _transition; }
            internal set { _transition = value; }
        }

        internal void Perform(TransitionOperationArguments args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            if (_transition == null)
                throw new WorkflowException("Should attach to a collection first.");

            if (args.Context.Stage != _transition.SourceStage || args.Context.Workflow != _transition.Workflow)
                throw new WorkflowException("Cannot process the specified step.");

            PerformCore(args);
        }

        protected abstract void PerformCore(TransitionOperationArguments args);

        public abstract TransitionTypes SupportedTransitionTypes { get; }

        public virtual bool Exclusive
        {
            get { return true; }
        }

        protected internal virtual string Token
        {
            get { return null; }
        }

    }
}
